package com.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.book.dao.TbBookDao;
import com.book.dao.TbLogDao;
import com.book.dao.TbTypeDao;
import com.book.entity.TbBook;
import com.book.entity.TbType;
import com.book.service.TbTypeService;
import com.book.vo.R;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbType)表服务实现类
 *
 * @author makejava
 * @since 2024-11-07 21:07:33
 */
@Service("tbTypeService")
@RequiredArgsConstructor
public class TbTypeServiceImpl implements TbTypeService {
    @Resource
    private final TbTypeDao tbTypeDao;
    private final StringRedisTemplate stringRedisTemplate;
    private final TbBookDao tbBookDao;
    private final TbLogDao tbLogDao;

    @Override
    public R findAll() {
        final List<TbType> list = tbTypeDao.selectList(new LambdaQueryWrapper<>());
        if (list!=null){
            return R.ok(list);
        }
        return R.fail("查询失败");
    }



    @Override
    public R findType(Integer typeId) {
        LambdaQueryWrapper<TbType> w = new LambdaQueryWrapper<>();
        w.eq(TbType::getValue,typeId);
        TbType tbType = tbTypeDao.selectOne(w);
        if (tbType!=null) {
//            LambdaQueryWrapper<TbBook> wrapper = new LambdaQueryWrapper<>();
//            wrapper.like(TbBook::getBookLei,"%" + "文学" + "%");
            // 爱上对方过后就哭了
            List<TbBook> list = tbBookDao.typeBook(tbType.getLabel());

            if (list != null) {
                return R.ok(list);
            }
        }
        return R.fail("查询图书类型失败");
    }
}

